﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Supersense.db;

namespace Supersense.content
{
    
    public class Faq
    {
        private Database db = new Database();

        public Faq()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }

        public DataView get_faq(int page)
        {
            int pagesize = 10;
            string sql = "select top " + pagesize + " * from sup_faq WHERE id not IN(select top " + (page - 1) * pagesize + " id from sup_faq ORDER BY settop DESC,publish_date DESC,id desc) ORDER BY settop DESC,publish_date DESC,id desc;";
            DataView dv = this.db.executedv(sql);
            if (dv != null)
            {
                return dv;
            }
            else
            {
                return null;
            }
        }

        public DataView get_faq(int page, int pagesize)
        {
            string sql = "select top " + pagesize + " * from sup_faq WHERE id not IN(select top " + (page - 1) * pagesize + " id from sup_faq ORDER BY settop DESC,publish_date DESC,id desc) ORDER BY settop DESC,publish_date DESC,id desc;";
            DataView dv = this.db.executedv(sql);
            if (dv != null)
            {
                return dv;
            }
            else
            {
                return null;
            }
        }

        public String get_faq(int type, int page, int pagesize, int from)
        {
            //string sql = "SELECT top " + pagesize * page + "  * FROM sup_spacenews WHERE type='" + type + "'";
            string sql = "select top " + pagesize + " * from sup_faq WHERE id not IN(select top " + (page - 1) * pagesize + " id from sup_faq ORDER BY settop DESC,publish_date DESC,id desc) ORDER BY settop DESC,publish_date DESC,id desc;";
            return sql;
            //DataView dv = this.db.executedv(sql);
            //if (dv != null)
            //{
            //    return dv;
            //}
            //else
            //{
            //    return null;
            //}
        }

        public bool delete(string ids)
        {
            string sql = "DELETE FROM sup_faq WHERE id IN(" + ids + ")";
            if (this.db.executesql(sql))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public string delete(int id,int s)
        {
            string sql = "DELETE FROM sup_faq WHERE id IN(" + id + ")";
            return sql;
            //if (this.db.executesql(sql))
            //{
            //    return true;
            //}
            //else
            //{
            //    return false;
            //}
        }

        public Hashtable pageinfo()
        {
            int pagesize = 2;
            string sql = "SELECT COUNT(*) as count FROM sup_faq";
            DataTable dt = this.db.executedt(sql);
            int count = int.Parse(dt.Rows[0]["count"].ToString().Trim());

            Hashtable ht = new Hashtable();
            ht.Add("records", count);
            return ht;
        }

        public bool update(string subject,string eventdate,string tags,string img,int settop,string content,string foreign_url,int newsid)
        {
            string sql = "UPDATE sup_spacenews SET subject='" + subject + "',eventdate='" + eventdate + "',tags='" + tags + "',settop=" + settop + ",text='" + content + "',foreign_url='" + foreign_url + "' WHERE id=" + newsid;
            if (this.db.executesql(sql))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public bool update(string subject, string eventdate, string img, int settop, string content,int newsid)
        {
            string sql = "UPDATE sup_spacenews SET subject='" + subject + "',eventdate='" + eventdate + "',settop=" + settop + ",text='" + content + "' WHERE id=" + newsid;
            if (this.db.executesql(sql))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }

}
